<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>FMC管理</el-breadcrumb-item>
      <el-breadcrumb-item>FMC用例</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card class="box-card">
      <!-- 搜索与添加区域 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input v-model="queryInfo.query"
                    class="input-with-select"
                    :clearable="true"
                    placeholder="请输入内容"
                    @clear="getCaseList"
                    @keyup.enter.native="getCaseList">
            <el-button slot="append"
                       icon="el-icon-search"
                       @click="getCaseList"></el-button>
          </el-input>
        </el-col>
        <el-col :span="2">
          <el-button type="primary"
                     @click="addDialogVisible = true">添加用例</el-button>
        </el-col>
        <el-col :span="2">
          <el-button type="primary"
                     @click="runallcase()">运行用例</el-button>
        </el-col>
      </el-row>
    </el-card>

    <!--  用户列表区域-->
    <el-table :data="tableData"
              :stripe="true"
              :border="true"
              style="width: 100%"
              @expand-change="expandpower(tableData.roleName)">
      <el-table-column type="expand"
                       width="50">
        <template slot-scope="props">
          <el-card>
            <el-row :gutter="24">
              <el-col :span="6">
                <el-row>{{props.row.role}}</el-row>
              </el-col>
              <el-col :span="18">456</el-col>
            </el-row>
          </el-card>
        </template>
      </el-table-column>
      <el-table-column type="index"
                       label="序号"
                       width="50">
      </el-table-column>
      <el-table-column prop="caseno"
                       label="用例编号"
                       width="80">
      </el-table-column>
      <el-table-column prop="casemodel"
                       label="用例模块"
                       width="80">
      </el-table-column>
      <el-table-column prop="casename"
                       label="用例名称"
                       width="180">
      </el-table-column>
      <el-table-column prop="method"
                       label="请求方式"
                       width="80">
      </el-table-column>
      <el-table-column prop="url"
                       label="请求地址"
                       width="180">
      </el-table-column>
      <el-table-column prop="api"
                       label="请求接口"
                       width="180">
      </el-table-column>
      <el-table-column prop="header"
                       label="请求头"
                       width="180">
      </el-table-column>
      <el-table-column prop="parameter"
                       label="请求param"
                       width="180">
      </el-table-column>
      <el-table-column prop="bodyString"
                       label="请求body"
                       width="180">
      </el-table-column>
      <el-table-column prop="isRun"
                       label="启用"
                       width="60">
      </el-table-column>
      <el-table-column prop="env"
                       label="环境"
                       width="60">
      </el-table-column>
      <el-table-column label="操作"
                       width="120">
        <template slot-scope="scope">
          <el-button @click="showEditDialog(scope.row.id)"
                     type="text"
                     size="small">编辑</el-button>
          <el-button @click="delconfirm(scope.row.id)"
                     type="text"
                     size="small">删除</el-button>
          <el-button @click="debugcase(scope.row)"
                     type="text"
                     size="small">调试</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页控件 -->
    <el-pagination @size-change="pagesizeChange"
                   @current-change="currentChange"
                   :current-page="queryInfo.pagenum"
                   :page-sizes="[1, 2, 5, 10]"
                   :page-size="queryInfo.pagesize"
                   layout="total, sizes, prev, pager, next, jumper"
                   :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'Basic',
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      tableData: [{}],
      roleData: [{}],
      expandrows: [],
      total: 0
    }
  },
  created () {
    this.getCaseList()
  },
  methods: {
    async getCaseList () {
      const { data: res } = await this.$http.get('/allcaselist', {
        params: this.queryInfo
      })
      if (res.code !== 200) {
        this.$message.error(res.message)
      }
      this.tableData = res.data.content
      this.total = res.data.pageInfo.total
      console.log(this.tableData)
    },
    async runallcase (row) {
      const { data: res } = await this.$http.get('/runallcase', {})
      if (res.code !== 200) {
        this.$message.error(res.message)
      }
    },
    async debugcase (row) {
      const { data: res } = await this.$http.get(`/roleOfPower1/${row.roleId}`, {})
      if (res.code !== 200) {
        this.$message.error(res.message)
      }
      this.roleData = res.data
      console.log(this.roleData)
    },
    expandpower (name) {
      console.log('zhankai' + name)
    },
    // 改变条数
    pagesizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getCaseList()
    },
    // 改变页码
    currentChange (newCurrent) {
      this.queryInfo.pagenum = newCurrent
      this.getCaseList()
    }
  }
}
</script>

<style>
</style>
